﻿using de.wolfmarco.pas.Accounting.Database;
using de.wolfmarco.pas.Shared.MessageBoxes;
using de.wolfmarco.pas.Shared.MVVM;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace de.wolfmarco.pas.Accounting.MVVM
{
    public class ScheduledCashFlowEditViewModel : EditWindowViewModel
    {
        private ScheduledCashFlow dto;

        public ScheduledCashFlowEditViewModel(ScheduledCashFlow dto)
            : base()
        {
            this.dto = dto;

            dto.PropertyChanged += dto_PropertyChanged;
        }

        private void dto_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            RaisePropertyChanged(e.PropertyName);
        }

        protected override void OnSave(object arg)
        {
            using (AccountingDbContext context = new AccountingDbContext())
            {
                dto.FetchEntity(context, context.ScheduledCashFlowList);

                context.SaveChanges();
            }
        }

        public string Description
        {
            get { return dto.Description; }
            set { dto.Description = value; }
        }

	    public CashFlowDirectionEnum Direction
	    {
		    get { return dto.Direction;}
		    set { dto.Direction = value; }
	    }

        public decimal AmountOfMoney
	    {
		    get { return dto.AmountOfMoney; }
		    set { dto.AmountOfMoney = value; }
	    }

        public CashFlowLoopEnum Loop
	    {
		    get { return dto.Loop;}
		    set { dto.Loop = value; }
	    }

        public CashFlowRhythmEnum Rhythm
	    {
		    get { return dto.Rhythm;}
		    set { dto.Rhythm = value; }
	    }

        public DateTime StartDate
	    {
		    get { return dto.StartDate; }
		    set { dto.StartDate = value; }
	    }

        public DateTime? EndDate
	    {
            get { return dto.EndDate; }
		    set { dto.EndDate = value; }
	    }
    }
}
